package com.sk.myview;


import java.util.HashMap;
import java.util.List;
import com.sk.water.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class TaskListAdapter extends BaseAdapter {
	private List<HashMap<String, String>> listData;
	private List<String> splitData;
	private LayoutInflater mInflater;
	private String tagName;

	private class TaskInfo {
		TextView taskName;
		TextView taskTime;
		TextView taskCount;
		ImageView taskStatu;
	}

	public TaskListAdapter(Context context,List<HashMap<String, String>> setedData, List<String> tags,String tagName) {
		this.listData = setedData;
		this.splitData = tags;
		this.tagName = tagName;
		this.mInflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return listData.size();
	}

	@Override
	public HashMap<String, String> getItem(int position) {
		// TODO Auto-generated method stub
		return listData.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public boolean isEnabled(int position) {
		// TODO Auto-generated method stub
		if (splitData.contains(getItem(position))) {
			return false;
		}
		return super.isEnabled(position);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = convertView;
		TaskInfo taskInfo = new TaskInfo();
		if (splitData.contains(getItem(position).get(tagName))) {
			view = mInflater.inflate(R.layout.today_taks_item_tag, null);
			TextView tagNametTextView = (TextView) view.findViewById(R.id.today_task_item_tag_name);
			tagNametTextView.setText(getItem(position).get(tagName));
		} else {
			view = mInflater.inflate(R.layout.today_task_item, null);
			taskInfo.taskName = (TextView) view.findViewById(R.id.today_task_item_name);
			taskInfo.taskTime = (TextView) view.findViewById(R.id.today_task_item_time);
			taskInfo.taskCount = (TextView) view.findViewById(R.id.today_task_item_count);
			taskInfo.taskStatu = (ImageView)view.findViewById(R.id.today_task_item_statu);
			taskInfo.taskName.setText(getItem(position).get("Name"));
			taskInfo.taskTime.setText(getItem(position).get("Time"));
			taskInfo.taskCount.setText(getItem(position).get("Count"));			
			if(getItem(position).get("Statu").equals("0")){
				taskInfo.taskStatu.setImageResource(R.drawable.task_item_undo);
			}else {
				taskInfo.taskStatu.setImageResource(R.drawable.task_item_done);
			}
		}
		return view;
	}
}
